package com.example.kafka.demo;


import java.util.Arrays;
import java.util.List;
import java.util.concurrent.CompletableFuture;

/**
 * @application:
 * @author: LiYuhang
 * @Date: 2021/6/26 15:33
 * @version: 0.1
 * @Description :
 * @Modified By:
 */
public class Demo1 {
    public static final String topic = "test";
    public static final String groupId = "topic.group2";

    public static void main(String[] args) {
        ConsumerDemo1 consumerDemo1 = new ConsumerDemo1(topic,groupId);
        com.example.kafka.demo.ProducerDemo1 producerDemo1 = new com.example.kafka.demo.ProducerDemo1(topic);

        List<CompletableFuture> futureList = startJob(consumerDemo1,producerDemo1);

        futureList.forEach(CompletableFuture::join);
    }


    private static List<CompletableFuture> startJob(ConsumerDemo1 consumerDemo1,com.example.kafka.demo.ProducerDemo1 producerDemo1) {
        CompletableFuture future1 = CompletableFuture.runAsync(() -> {
            producerDemo1.run();
        });
        CompletableFuture future2 = CompletableFuture.runAsync(() -> {
            consumerDemo1.run();
        });
        return Arrays.asList(future1,future2);
    }
}
